package com.example.ovulationperiodtracker.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.databinding.ViewChartTabBinding;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

public class ChartTabView extends FrameLayout {

    int[] iconSelectIds = {R.mipmap.tab11, R.mipmap.tab31, R.mipmap.tab21, R.mipmap.tab41};

    int[] iconUnselectIds = {R.mipmap.tab10, R.mipmap.tab20, R.mipmap.tab30, R.mipmap.tab40};
    String[] titles = {"月经周期", "经期", "体重", "体温"};

    private ViewChartTabBinding binding;

    public ChartTabView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        binding = ViewChartTabBinding.inflate(LayoutInflater.from(context), this, true);


        ArrayList<CustomTabEntity> tabEntities = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            tabEntities.add(new TabEntity(titles[i], iconSelectIds[i], iconUnselectIds[i]));
        }
        binding.xinqingLayout.setTabData(tabEntities);
        binding.xinqingLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (onChartTabListener != null) {
                    onChartTabListener.onClickTab(position);
                }
            }

            @Override
            public void onTabReselect(int position) {
                // 如果需要处理重复点击同一个Tab的事件，可以在这里实现
            }
        });

    }


    private OnChartTabListener onChartTabListener;

    public ChartTabView setOnChartTabListener(OnChartTabListener onChartTabListener) {
        this.onChartTabListener = onChartTabListener;
        return this;
    }

    public interface OnChartTabListener {
        void onClickTab(int position);
    }
}
